from plugin import plugin
import random, plugins

__doc__ = "rng"

class rng(plugin):
	"Provides methods for choice"
	
	def __init__(self):
		self._version = '3.0 stable'

	@plugins.irc_throw
	def rand(self, msg, args):
		"Get a random number. Usage: .rand ([min]) [max] (e.g. .rand or .rand 10 or .rand 1 10)"
		min, max = 0, 100
		if len(args) > 0:
			if args.count(' ') == 1:
				list = args.split()
				try:
					min = int(list[0])
					max = int(list[1])
				except:
					return 'Numbers only! No funny.'
			elif args.count(' ') == 0:
				try: max = int(args)
				except: return 'Numbers only! No funny.'
			else:
				self._irc.reply(msg, 'Usage: .rand [min] max')

		result = random.randint(min, max)
		self._irc.reply(msg, str(result))

	def roll(self, msg, args):
		"Roll a dice! Returns a random number between 1 and 6. Usage: .roll"
		result = random.randint(0, 6)
		self._irc.reply(msg, str(result))

	@plugins.irc_throw
	def choose(self, msg, args):
		"Choose between a list of things. Usage: .choose [list] (e.g. .choose pizza, asda"
		if args.count(' ') < 1:
			return 'Error! must have more than one argument!'
		list = args.split(',')
		self._irc.reply(msg, random.choice(list))
